package edu.hbsi.demo4;

public class Tryself {
    public void calc(byte k) throws OverflowException{
        byte y=1,i=1;
        System.out.println(k+"!=");
        for(i=1;i<-k;i++){
            if(y>Byte.MAX_VALUE/i){
                throw new OverflowException();
            }else{
                y=(byte)(y*i);
            }
        }
        System.out.println(y);
    }

    public static void main(String[] args) {
        Tryself t=new Tryself();
        for(byte i=1;i<8;i++){
            try{
                t.calc(i);
            }catch(OverflowException e){
                System.out.println("出现异常："+e.getMessage());
            }
        }
    }

}
